﻿using Microsoft.Extensions.DependencyInjection;
using TaskTodo.Todos;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.MySQL;
using Volo.Abp.Modularity;

namespace TaskTodo.EntityFrameworkCore
{
    [DependsOn(
        typeof(TaskTodoDomainModule),
        typeof(AbpEntityFrameworkCoreModule),
        typeof(AbpEntityFrameworkCoreMySQLModule)
    )]
    public class TaskTodoEntityFrameworkCoreModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddSingleton<Yitter.IdGenerator.IIdGenerator, Yitter.IdGenerator.DefaultIdGenerator>(options =>
            {
                return new Yitter.IdGenerator.DefaultIdGenerator(new Yitter.IdGenerator.IdGeneratorOptions(1));
            });

            context.Services.AddAbpDbContext<TaskTodoDbContext>(options =>
            {
                /* Add custom repositories here. Example:
                 * options.AddRepository<Question, EfCoreQuestionRepository>();
                 */
                options.AddRepository<Todo, TodoRepository>();
            });
            Configure<AbpDbContextOptions>(options =>
            {
                options.UseMySQL();
            });
        }
    }
}